const { orderFormatError } = require('../constant/err.type')

const paramValidator = (rules) => {
    return async (ctx, next) => {
        try {
            ctx.verifyParams(rules)
        } catch (error) {
            // 错误处理
            console.error(error)
            orderFormatError.result = error
            return ctx.app.emit('error', orderFormatError, ctx)
        }
        await next()
    }
}

module.exports = {
    paramValidator
}